﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.Common;
using System.Data.SQLite;

/// <summary>
///SQLiteDBConnector 的摘要说明
/// </summary>
public class SQLiteDBConnector : DBConnectorBase
{
    //public string SQLITE_FILE_NAME = "E:\\Users\\Administrator\\Desktop\\WebSite\\App_Data\\test.db";
    public const string SQLITE_FILE_NAME = "test.db";

	public SQLiteDBConnector()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    public override DbConnection GetConnection()
    {
        string sqlite_path = HttpRuntime.AppDomainAppPath.ToString() + "App_Data\\" + SQLITE_FILE_NAME;
        SQLiteConnection conn = new SQLiteConnection();
        SQLiteConnectionStringBuilder connstr = new SQLiteConnectionStringBuilder();
        connstr.DataSource = sqlite_path;
        conn.ConnectionString = connstr.ToString();
        conn.Open();
        return conn;
    }

    public override DbDataAdapter GetDataAdapter(string cmd)
    {
        DbConnection conn = GetConnection();
        SQLiteCommand command = new SQLiteCommand();
        command.CommandText = cmd;
        command.Connection = (SQLiteConnection)conn;
        SQLiteDataAdapter da = new SQLiteDataAdapter(command);
        if (conn.State == ConnectionState.Open)
        {
            conn.Close();
        }
        return da;
    }

    public override string DateTimeToString(DateTime time_to_convert)
    {
        return time_to_convert.ToString("s");
    }
}
